// ----------------------------------------
// Filename: Queue_Testing
// Description: the unit testing of the message Queue
// Author: Jon Maloney
// Date: 11-Jun-2012
//

//************************************************************
//                    Include .h files
//************************************************************
#include "Queue_Testing.h"
#include "thread.h"
#include "Scheduler.h"
#include "mqueue.h"
#include <stdio.h>
#include <stdlib.h>
//************************************************************
//                    Include external references
//************************************************************

//************************************************************
//                    Define Statements
//************************************************************

//************************************************************
//                    Struct, Union, enum Statements
//************************************************************

//************************************************************
//                    Global variables and constants
//************************************************************

//************************************************************
//                    Prototype Private Functions
//************************************************************

void producer(void * functionArgument);
void consumer(void * functionArgument);

//************************************************************
//                    Implementation
//************************************************************

//************************************************************
//                    Test Description
//
//
//
//************************************************************
void queueTest(void)
{
	Thread_Create(producer, NULL, 200, 1);
}

// ----------------------------------------
// producer
// 
// In this test case 'producer' produces a number
//	and sends this number to 'consumer'
// Input:
//  none
// Output:
//   none
// Conditions:
// 	none
void producer(void * functionArgument)
{
	UINT16 wordToSend;
	m_QueueHandle mQueue = mqueue_Create(10, sizeof(UINT16));
	Thread_Create(consumer, mQueue, 200, 2);
	

	while(1)
	{
		printf("Producer sent %d \n", wordToSend);
		mqueue_Put(mQueue, &wordToSend, 1000);
		wordToSend++;
		Scheduler_Delay(1000);//Delay for 1 s
	}
}

// ----------------------------------------
// consumer
// 
//	Consumer will receive a number generated 
//	by producer. This number will then be printed
//	to the SIM Uart1.
// Input:
//  none
// Output:
//   none
// Conditions:
// 	none
void consumer(void * functionArgument)
{
	UINT16 wordReceived;
	m_QueueHandle mQueue = (m_QueueHandle)functionArgument;
	while(1)
	{
		if(mqueue_Get(mQueue, &wordReceived, 1200) == pdTRUE);
			printf("Consumer received %d \n", wordReceived);
	}
}
